﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace DataModelLibrary
{
    public class SqlSugarClientHelper
    {
        private static SqlSugarClientHelper _instance;

        private SqlSugarClientHelper() { }

        private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static SqlSugarClientHelper Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new SqlSugarClientHelper();
                return _instance;
            }
        }


        public SqlSugarClient ConnectDb() 
        {

            SqlSugarClient db = null;

            try 
            {
                // 设置连接字符串
                string connectionString = "server=192.168.112.222;database=AimiraShaoLuDB;uid=root;pwd=123456;charset=utf8;";

                // 创建SqlSugar对象
                db = new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString = connectionString,
                    DbType = DbType.MySql,
                    IsAutoCloseConnection = true
                });

                Logger.Info("数据库连接成功！");

            }
            catch(Exception ex)
            {
                Logger.Error(ex.Message);
            }
           
            return db;
        }



    }
}
